﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Text;

namespace RRTWSDSD.ServiceUtilidad
{
    /// <summary>
    /// Summary description for ConvertirCadenaEnArregloService
    /// </summary>
    [WebService(Namespace = "http://rtt.edu.upc.com.pe/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class ConvertirCadenaEnArregloService : System.Web.Services.WebService
    {

        [WebMethod]
        public int[] convertir(string strArreglo)
        {
            if ((strArreglo != null) && (strArreglo.Length > 0) )
            {
                string[] words = strArreglo.Split(',');
                int[] retrunArray = new int[words.Length];

                for (int i = 0; i < words.Length; i++)
                {
                    retrunArray[i] = Int32.Parse(words[i]);
                }
                return retrunArray;
            }
            return null;
        }

        [WebMethod]
        public string revertir(int[] arregloEnteros)
        {
            if ((arregloEnteros != null) && (arregloEnteros.Length > 0))
            {
            return convertStringArrayToString(arregloEnteros);
            }
            return "";
        }

        static string convertStringArrayToString(int[] array)
        {
            if ((array != null) && (array.Length > 0))            
            {
                if ((array.Length == 1)) {
                    return array[0].ToString();
                } 
            }
            string idString = String.Join(",", array);
            return idString;
        }
    }
}
